//
// SoapTrace.Net - A soap message monitoring utility. 
//
// Copyright (C) 2005 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Matthew Ward (mrward@users.sourceforge.net)


using System;
using System.Collections;

namespace SoapTrace.Core.Formatters
{
	/// <summary>
	///   A collection that stores <see cref='FormattedTextItem'/> objects.
	/// </summary>
	[Serializable()]
	public class FormattedTextItemCollection : CollectionBase {
		
		/// <summary>
		///   Initializes a new instance of <see cref='FormattedTextItemCollection'/>.
		/// </summary>
		public FormattedTextItemCollection()
		{
		}
		
		/// <summary>
		///   Initializes a new instance of <see cref='FormattedTextItemCollection'/> based on another <see cref='FormattedTextItemCollection'/>.
		/// </summary>
		/// <param name='val'>
		///   A <see cref='FormattedTextItemCollection'/> from which the contents are copied
		/// </param>
		public FormattedTextItemCollection(FormattedTextItemCollection val)
		{
			this.AddRange(val);
		}
		
		/// <summary>
		///   Initializes a new instance of <see cref='FormattedTextItemCollection'/> containing any array of <see cref='FormattedTextItem'/> objects.
		/// </summary>
		/// <param name='val'>
		///       A array of <see cref='FormattedTextItem'/> objects with which to intialize the collection
		/// </param>
		public FormattedTextItemCollection(FormattedTextItem[] val)
		{
			this.AddRange(val);
		}
		
		/// <summary>
		///   Represents the entry at the specified index of the <see cref='FormattedTextItem'/>.
		/// </summary>
		/// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
		/// <value>The entry at the specified index of the collection.</value>
		/// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
		public FormattedTextItem this[int index] {
			get {
				return ((FormattedTextItem)(List[index]));
			}
			set {
				List[index] = value;
			}
		}
		
		/// <summary>
		///   Adds a <see cref='FormattedTextItem'/> with the specified value to the 
		///   <see cref='FormattedTextItemCollection'/>.
		/// </summary>
		/// <param name='val'>The <see cref='FormattedTextItem'/> to add.</param>
		/// <returns>The index at which the new element was inserted.</returns>
		/// <seealso cref='FormattedTextItemCollection.AddRange'/>
		public int Add(FormattedTextItem val)
		{
			return List.Add(val);
		}
		
		/// <summary>
		///   Copies the elements of an array to the end of the <see cref='FormattedTextItemCollection'/>.
		/// </summary>
		/// <param name='val'>
		///    An array of type <see cref='FormattedTextItem'/> containing the objects to add to the collection.
		/// </param>
		/// <seealso cref='FormattedTextItemCollection.Add'/>
		public void AddRange(FormattedTextItem[] val)
		{
			for (int i = 0; i < val.Length; i++) {
				this.Add(val[i]);
			}
		}
		
		/// <summary>
		///   Adds the contents of another <see cref='FormattedTextItemCollection'/> to the end of the collection.
		/// </summary>
		/// <param name='val'>
		///    A <see cref='FormattedTextItemCollection'/> containing the objects to add to the collection.
		/// </param>
		/// <seealso cref='FormattedTextItemCollection.Add'/>
		public void AddRange(FormattedTextItemCollection val)
		{
			for (int i = 0; i < val.Count; i++)
			{
				this.Add(val[i]);
			}
		}
		
		/// <summary>
		///   Gets a value indicating whether the 
		///    <see cref='FormattedTextItemCollection'/> contains the specified <see cref='FormattedTextItem'/>.
		/// </summary>
		/// <param name='val'>The <see cref='FormattedTextItem'/> to locate.</param>
		/// <returns>
		/// <see langword='true'/> if the <see cref='FormattedTextItem'/> is contained in the collection; 
		///   otherwise, <see langword='false'/>.
		/// </returns>
		/// <seealso cref='FormattedTextItemCollection.IndexOf'/>
		public bool Contains(FormattedTextItem val)
		{
			return List.Contains(val);
		}
		
		/// <summary>
		///   Copies the <see cref='FormattedTextItemCollection'/> values to a one-dimensional <see cref='Array'/> instance at the 
		///    specified index.
		/// </summary>
		/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='FormattedTextItemCollection'/>.</param>
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
		/// <exception cref='ArgumentException'>
		///   <para><paramref name='array'/> is multidimensional.</para>
		///   <para>-or-</para>
		///   <para>The number of elements in the <see cref='FormattedTextItemCollection'/> is greater than
		///         the available space between <paramref name='arrayIndex'/> and the end of
		///         <paramref name='array'/>.</para>
		/// </exception>
		/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
		/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
		/// <seealso cref='Array'/>
		public void CopyTo(FormattedTextItem[] array, int index)
		{
			List.CopyTo(array, index);
		}
		
		/// <summary>
		///    Returns the index of a <see cref='FormattedTextItem'/> in 
		///       the <see cref='FormattedTextItemCollection'/>.
		/// </summary>
		/// <param name='val'>The <see cref='FormattedTextItem'/> to locate.</param>
		/// <returns>
		///   The index of the <see cref='FormattedTextItem'/> of <paramref name='val'/> in the 
		///   <see cref='FormattedTextItemCollection'/>, if found; otherwise, -1.
		/// </returns>
		/// <seealso cref='FormattedTextItemCollection.Contains'/>
		public int IndexOf(FormattedTextItem val)
		{
			return List.IndexOf(val);
		}
		
		/// <summary>
		///   Inserts a <see cref='FormattedTextItem'/> into the <see cref='FormattedTextItemCollection'/> at the specified index.
		/// </summary>
		/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
		/// <param name='val'>The <see cref='FormattedTextItem'/> to insert.</param>
		/// <seealso cref='FormattedTextItemCollection.Add'/>
		public void Insert(int index, FormattedTextItem val)
		{
			List.Insert(index, val);
		}
		
		/// <summary>
		///  Returns an enumerator that can iterate through the <see cref='FormattedTextItemCollection'/>.
		/// </summary>
		/// <seealso cref='IEnumerator'/>
		public new FormattedTextItemEnumerator GetEnumerator()
		{
			return new FormattedTextItemEnumerator(this);
		}
		
		/// <summary>
		///   Removes a specific <see cref='FormattedTextItem'/> from the <see cref='FormattedTextItemCollection'/>.
		/// </summary>
		/// <param name='val'>The <see cref='FormattedTextItem'/> to remove from the <see cref='FormattedTextItemCollection'/>.</param>
		/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
		public void Remove(FormattedTextItem val)
		{
			List.Remove(val);
		}
		
		/// <summary>
		///   Enumerator that can iterate through a FormattedTextItemCollection.
		/// </summary>
		/// <seealso cref='IEnumerator'/>
		/// <seealso cref='FormattedTextItemCollection'/>
		/// <seealso cref='FormattedTextItem'/>
		public class FormattedTextItemEnumerator : IEnumerator
		{
			IEnumerator baseEnumerator;
			IEnumerable temp;
			
			/// <summary>
			///   Initializes a new instance of <see cref='FormattedTextItemEnumerator'/>.
			/// </summary>
			public FormattedTextItemEnumerator(FormattedTextItemCollection mappings)
			{
				this.temp = ((IEnumerable)(mappings));
				this.baseEnumerator = temp.GetEnumerator();
			}
			
			/// <summary>
			///   Gets the current <see cref='FormattedTextItem'/> in the <seealso cref='FormattedTextItemCollection'/>.
			/// </summary>
			public FormattedTextItem Current {
				get {
					return ((FormattedTextItem)(baseEnumerator.Current));
				}
			}
			
			object IEnumerator.Current {
				get {
					return baseEnumerator.Current;
				}
			}
			
			/// <summary>
			///   Advances the enumerator to the next <see cref='FormattedTextItem'/> of the <see cref='FormattedTextItemCollection'/>.
			/// </summary>
			public bool MoveNext()
			{
				return baseEnumerator.MoveNext();
			}
			
			/// <summary>
			///   Sets the enumerator to its initial position, which is before the first element in the <see cref='FormattedTextItemCollection'/>.
			/// </summary>
			public void Reset()
			{
				baseEnumerator.Reset();
			}
		}
	}
}
